package com.wyzz.hr.interceptor;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import com.wyzz.hr.base.Constants;
import com.wyzz.hr.pojo.Userinfo;
import com.wyzz.hr.util.MyTools;

import java.util.Map;
import javax.servlet.http.HttpServletRequest;

public class LoginCheck implements Interceptor, Constants {

	public LoginCheck() {
	}

	public void destroy() {
	}

	public void init() {
	}

	public String intercept(ActionInvocation actionInvocation) throws Exception {
		ActionContext ctx = actionInvocation.getInvocationContext();
		Map session = ctx.getSession();
		Userinfo userinfo = (Userinfo) session.get("userinfo");
		if (userinfo == null)
			try {
				session
						.put(
								"requiredURL",
								MyTools
										.getFromURL((HttpServletRequest) ctx
												.get("com.opensymphony.xwork2.dispatcher.HttpServletRequest")));
			} catch (Exception e) {
			}
		return userinfo != null ? actionInvocation.invoke() : "login";
	}

	private static final long serialVersionUID = 1L;
}
